﻿using System;
using KryptecizerBase;
using Kryptonalysis.Rank;

namespace Kryptonalysis
{
    /// <summary>
    /// Analyzer for KryptoTexts encrypted with Caesar-algorithm.
    /// </summary>
    public class CaesarAnalyzer : TextBasedAnalyzer
    {
        /// <summary>
        /// Method to detect the password.
        /// </summary>
        /// <param name="kryptoText">The krypto text.</param>
        /// <returns>the password</returns>
        protected override string DetectPassword(KryptoText kryptoText)
        {
            SelffillingLetterRanks textRanks = new SelffillingLetterRanks(kryptoText);
            GermanLetterRanks ger = new GermanLetterRanks();

            int textAscii = (int)(textRanks.GetByRank(1).Sign);
            int gerAscii = (int)(ger.GetByRank(1).Sign);
            return (textAscii - gerAscii).ToString();
        }
    }
}
